package com.dengqi.mymodule.activity.loader.bitmap;

import android.app.ProgressDialog;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.dengqi.mymodule.BaseActivity;
import com.dengqi.mymodule.R;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 *
 */
public class LoaderBitmapActivity extends BaseActivity implements BitmapCollection.BitmapCallbacks {


    @BindView(R.id.image)
    ImageView image;
    private BitmapCollection mCollection;
    private ProgressDialog progressDialog;
    private String url = "http://desk.fd.zol-img.com.cn/t_s1920x1080/g2/M00/0D/0F/ChMlWlyJq3WIFK4ZAAYH7JAhXXcAAIx6wGV39YABggE583.jpg";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_loader_bitmap);
        ButterKnife.bind(this);

        mCollection = new BitmapCollection();
        mCollection.init(LoaderBitmapActivity.this, LoaderBitmapActivity.this);

        progressDialog = new ProgressDialog(this);
        progressDialog.setTitle("提示信息");
        progressDialog.setMessage("正在下载中，请稍后......");
        //    设置setCancelable(false); 表示我们不能取消这个弹出框，等下载完成之后再让弹出框消失
        progressDialog.setCancelable(true);
        //    设置ProgressDialog样式为圆圈的形式
        progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    }

    public void onBtn1(View view) {
        progressDialog.show();
        mCollection.startLoad(url);
    }

    @Override
    public void onBitmapLoad(Bitmap bitmap) {
        progressDialog.dismiss();
        image.setImageBitmap(bitmap);
    }

    @Override
    public void onBitmapReset() {

    }

    @Override
    public void onProgressUpdate(int progress) {
        progressDialog.setProgress(progress);
    }
}
